package core_sql.day02.homework

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * 每个学科中最喜爱的老师
  */
object Teacher2 {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("teacher").setMaster("local[*]")
    val sc: SparkContext = new SparkContext(conf)

    val file: RDD[String] = sc.textFile("src/main/file/teacher.log")

    val sub_teacher_One: RDD[((String, String), Int)] = file.map(line => {
      val split: Array[String] = line.split("/")
      ((split(2), split(3)), 1)
    })
    val key: RDD[((String, String), Int)] = sub_teacher_One.reduceByKey(_+_).coalesce(1)

    val sorted: RDD[((String, String), Int)] = key.sortBy( t=> t._2)

    sorted.foreach(println(_))


  }

}
